package com.labreeze.spring.aop.advisor;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import org.springframework.aop.ClassFilter;
import org.springframework.aop.support.DynamicMethodMatcherPointcut;

import com.labreeze.spring.aop.advice.Waiter;

public class DynamicAdvisor extends DynamicMethodMatcherPointcut {

	private static List<String> nameList = new ArrayList<String>();
	static {
		nameList.add("mary");
		nameList.add("telor");
	}

	@Override
	public boolean matches(Method method, Class<?> targetClass) {
		// TODO Auto-generated method stub	
		System.out.println(targetClass.getClass().getName()+"."+method.getName()+"做静态检查");
		return "greetTo".equals(method.getName());
	}
	
	public boolean matches(Method method, Class<?> targetClass, Object[] args) {
		// TODO Auto-generated method stub
		System.out.println(targetClass.getClass().getName()+"."+method.getName()+"做动态检查");
		String name=(String)args[0];
		return nameList.contains(name);
	}


	@Override
	public ClassFilter getClassFilter() {
		// TODO Auto-generated method stub
		return new ClassFilter() {

			public boolean matches(Class<?> clazz) {
				// TODO Auto-generated method stub
				return Waiter.class.isAssignableFrom(clazz);
			}
		};
	}

}
